package experiment;

import java.util.*;

//一个员工列表，存储所有员工的信息
public class EmployeeList {
    private static final List<Employee> employees= new ArrayList<>();
    private static final List<String> employeesName = new ArrayList<>();
    //员工信息的录入
    static{
        employees.add(new Employee("0001","李治国","男","1990-01-29", new Department("102","市场部")));
        employees.add(new Employee("0002","王建","男","1993-09-12",new Department("101","技术部")));
        employees.add(new Employee("0103","张宇轩","男","1999-04-26",new Department("103","运营部")));
        employees.add(new Employee("0098","陈晓晓","女","1998-07-31",new Department("102","市场部")));
        employees.add(new Employee("0100","冯小军","男","1997-09-12",new Department("103","运营部")));
        employees.add(new Employee("0110","陈沫羽","女","2001-10-01",new Department("104","销售部")));
        employees.add(new Employee("0027","秦霞","女","1996-08-23",new Department("102","市场部")));
        employees.add(new Employee("0111","白娟","女","2001-01-30",new Department("101","技术部")));
        employees.add(new Employee("0132","吴嘉琪","男","2002-03-04",new Department("101","技术部")));
        employees.add(new Employee("0099","郑宇","男","1999-04-02",new Department("101","技术部")));

        employeesName.add("李治国");
        employeesName.add("王建");
        employeesName.add("张宇轩");
        employeesName.add("陈晓晓");
        employeesName.add("冯小军");
        employeesName.add("陈沫羽");
        employeesName.add("秦霞");
        employeesName.add("白娟");
        employeesName.add("吴嘉琪");
        employeesName.add("郑宇");
    }
    //显示员工
    public void showEmployee(){
        Iterator<Employee> iterator = employees.iterator();
        while(iterator.hasNext()){
            Employee employee = iterator.next();
            System.out.println(employee);
        }
    }
    //将添加的员工信息加到员工列表里，将员工姓名添加到员工姓名列表里
    public void addEmployee(Employee employee){
        employees.add(employee);
        employeesName.add(employee.getName());
    }

    //判断该员工是否存在
    public boolean isEmployeeContains(String name){
        if(employeesName.contains(name)){
            return true;
        }
        return false;
    }

    //查找该员工
    public Employee findEmployeeName(String name){
        if(employeesName.contains(name)){
            Iterator<Employee> iterator = employees.iterator();
            while(iterator.hasNext()){
                Employee employee = iterator.next();
                if(employee.getName().equals(name)){
                    return employee;
                }
            }
        }else{
            System.out.println("该员工不存在！");
        }
        return null;
    }
    public boolean findEmployee(String name){
        Employee employee = findEmployeeName(name);
        return !(employee == null);
    }

    //删除员工
    public boolean removeEmployee(String name){
        Employee employee = findEmployeeName(name);
        if(employee == null){
            return false;
        }else{
            employees.remove(employee);
            employeesName.remove(name);
            return true;
        }
    }
    //修改员工信息
    public void updateEmployee(String name,String coding,String sex,String birth,Department department){
        Employee employee = findEmployeeName(name);
        employee.setBirth(birth);
        employee.setCoding(coding);
        employee.setSex(sex);
        employee.setDepartment(department);
    }

}
